package com.study.Pool;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 */
public class ThreadPoolDemo {
    public static void main(String[] args) {

        ExecutorService executorService= Executors.newCachedThreadPool();//快
        ExecutorService executorService1 = Executors.newFixedThreadPool(10);//慢
        ExecutorService executorService2 = Executors.newSingleThreadExecutor();//最慢
        for (int i = 1; i <=100 ; i++) {
            executorService2.execute(new MyTask(i));
        }

    }
  static class MyTask implements Runnable{
        int i=0;
        MyTask(int i){
            this.i=i;
        }
      @Override
      public void run() {
          System.out.println(Thread.currentThread().getName()+"程序员做第"+i+"个项目");
          try{
              Thread.sleep(10000L);

          }catch (Exception e){
              e.printStackTrace();
          }
      }
  }
}
